#ifndef __IReferenceCounted_H__
#define __IReferenceCounted_H__

#include "base_type_vendor.h"

namespace lampe{

class IReferenceCounted{
private:
	mutable lampe::u32 ref_count;
public:
	IReferenceCounted():ref_count(1){
	}
	virtual ~IReferenceCounted(){
	}

	void grab() const{
		++ref_count;
	}

	bool drop() const{
		if (ref_count==0){
			return false;
		}
		--ref_count;
		if (!ref_count){
			delete this;
			return true;
		}

		return false;
	}

	u32 getReferenceCount()const{
		return ref_count;
	}
};

}//namespace lampe
#endif
